<template>
  <div class="">
    <el-dialog :title="$tt('label_add_supplier')" append-to-body :visible.sync="dialogVisible">
      <ex_super_table_page v-bind="option" @selection-change="(e) => (selection = e)" ref="SuperTablePage" />
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">{{ $tt('label_cancel') }}</el-button>
        <el-button type="primary" @click="submit">{{ $tt('label_confirm') }}</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import superTablePageFunction from "@/mixin/super-table-page-function";
import page_table_model_manage from "@/mixin/page_table_model_manage";
export default {
  components: {},
  mixins: [
    superTablePageFunction,
    // emitOnFunction(emitKey),
    page_table_model_manage,
  ],
  props: {
    dialogData: Object,
  },
  data() {
    return {
      dialogVisible: false,
      tableData: [],
      option: {
        style: {
          height: "500px",
        },
        search: {
          default: {
            customerId: this.dialogData.customerId,
          },
          model: [
            {
              label: "label_supplier_good_name",
              key: "supplierName",
            },
          ],
        },
        table: {
          url: "/oms-api/purchase/OmsPurchaseSupplierRpc/selectPage.json",
          attrs: {},
          model: this.init_table_model(),
        },
      },
    };
  },
  watch: {},
  computed: {},
  created() { },
  mounted() { },
  methods: {
    show() {
      this.dialogVisible = true;
      // 新增供应商
      // 新增商品
    },
    option_table_model() {
      return [
        {
          type: "selection",
          clickToggle: true,
          keyGroup: "label_table_operate",
        },
        {
          key: "supplierName",
          label: "label_supplier_good_name",
          "min-width": 130,
          "show-overflow-tooltip": true,
        },
        {
          key: "supplierOnlyCode",
          label: "label_supplier_vendor_unique_code",
          "min-width": 180,
        },
        {
          key: "customerCode",
          label: "label_customer_code",
          "min-width": 130,
          "show-overflow-tooltip": true,
        },
      ];
    },
    submit() {
      if (!this.selection || this.selection.length === 0) {
        return
      }
      const bindingDetailList = [];
      this.selection.forEach(item => {
        bindingDetailList.push({
          isFirstChoice: "Y",
          supplierOnlyCode: item.supplierOnlyCode,
          skuOnlyCode: this.dialogData.skuOnlyCode,
        });
      })
      this.$ajax({
        url: "/oms-api/purchase/OmsPurchaseSupplierRefRpc/addSupplierRef.json",
        type: 'json',
        data: { bindingDetailList },
        success: (res) => {
          if (res.code === 0) {
            this.$refs.SuperTablePage.clearSelection();
            this.dialogVisible = false
            this.$message.success(this.$tt('tip_operate_success'))
            this.$emit('getList')
          }
        },
      });
    },
  },
  destroyed() { },
};
</script>

<style lang="less" scoped></style>
